package com.winit.schedule.demo.taskdeal;

import java.util.ArrayList;
import java.util.List;

import com.winit.schedule.core.model.Task;
import com.winit.schedule.core.task.ScheduleTaskDealMulti;
import com.winit.schedule.core.task.annotation.ScheduleTask;

@ScheduleTask(taskName = "demoTaskMulti")
public class OrderTaskDealMulti implements ScheduleTaskDealMulti<OrderInfo> {

    int count = 0;

    @Override
    public List<OrderInfo> selectTasks(Task task) {

        count++;
        if (count % 3 == 0) {
            return null;
        }

        List<OrderInfo> orders = new ArrayList<OrderInfo>();
        for (int i = 0; i < task.getEachFetchDataNum(); i++) {

            orders.add(new OrderInfo("orderId-" + i * count, "orderName-" + i * count));
        }
        return orders;
    }

    @SuppressWarnings("static-access")
    @Override
    public boolean execute(OrderInfo[] t) {
        try {
            Thread.currentThread().sleep(500);
            // System.out.println(">>>>>>>>>>>>>>>>>" + t.getOrderId());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return true;
    }

}
